import javax.swing.*;
import java.awt.*;
import java.awt.Toolkit;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class crush1 {
    private static final String[] TIPS = {
            "记得吃早饭", "你其实不胖", "不用再减肥了",
            "保持微笑", "别熬夜，早点睡觉", "记得多加衣服",
            "记得带伞", "岁寒，时深，添衣，想我"
    };
    private static final Color[] BG_COLORS = {
            new Color(255, 182, 193),
            new Color(135, 206, 235),
            new Color(144, 228, 144),
            new Color(230, 230, 250),
            new Color(255, 255, 224),
            new Color(221, 160, 221),
            new Color(255, 127, 80),
            new Color(255, 228, 196),
            new Color(127, 255, 212),
            new Color(255, 228, 225),
            new Color(240, 255, 240),
            new Color(255, 240, 245),
            new Color(253, 245, 230),
    };

    private static void createTipWindow() {
        Random random = new Random();
        JFrame frame = new JFrame("温馨提示");
        frame.setSize(300, 100);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int x = random.nextInt(screenSize.width - 300);
        int y = random.nextInt(screenSize.height - 150);
        frame.setLocation(x, y);
        Color bgColor = BG_COLORS[random.nextInt(BG_COLORS.length)];
        JLabel label =new JLabel(TIPS[random.nextInt(TIPS.length)],
        SwingConstants.CENTER);
        label.setFont(new Font("微软雅黑",Font.PLAIN,22));
        label.setOpaque(true);
        label.setBackground(bgColor);
        label.setPreferredSize(new Dimension(300, 150));
        frame.add(label);
        frame.setAlwaysOnTop(true);
        frame.setVisible(true);
    }

    static void main() {
        ExecutorService executor = Executors.newSingleThreadExecutor();

        for (int i = 0; i < 100; i++) {
            executor.submit(() -> {
                try {
                    Thread.sleep(150);
                    SwingUtilities.invokeLater(crush1::createTipWindow);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            });
        }
    }




    }




